********************************************************************************
********************************************************************************
* NATIVE OUTFLOWS
********************************************************************************
********************************************************************************

use "$data/propval.dta", clear
set more off

* CREATE VARIABLES OF INTEREST

	// Area level
*gen migch_a = mig_change_all / poplag *100	// first differences
gen migch_apl = totmig / totpop13 *100	// levels

	// Native stock
gen totnat = totpop - totmig if totmig!=.
	
******************************************************************************** 
*Estimates across areas
******************************************************************************** 

* AGREGATE DATA
collapse (mean) totnat totpop13 migch_apl IV2005_pl [pw=fex12], by(area year)

* LOG DEPENDENT VARIABLE
gen lnat = log(totnat)

* DEFINE VARIABLES
global y 	lnat
global x 	migch_apl
global z	IV2005_pl
global w 	totpop13

* REGRESSIONS
tsset area year

qui areg $y $x i.year [aw = $w], abs(area) robust
	estimates store ols_a, title (OLS)
	
qui ivreg2 $y ($x = $z) i.year i.area [aw = $w], robust first small partial(i.area)
	estimates store iv_a, title (2SLS)
	matrix list e(first)				// Store results for tables
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]	// Kleiberger-paap rk Wald F-stat

* TABULATE RESULTS
esttab ols_a iv_a ,  keep($x) ///
star(* 0.10 ** 0.05 *** 0.01)  b(3) se(3)  ///
coeflabels($x "(log) Native stock") ///
mlabels( , titles) collabels(none) obslast varwidth(20)  modelwidth(15) ///
scalars("Fstat Kleibergen-Paap F") ///
title("Variation across areas")

